﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.Auth;
using Zhp.IService.Chat;
using Zhp.Model.Chat;
using Zhp.Model.Common;

namespace Zhp.Api.Controllers.Chat
{
    [Route("api/[controller]/[action]")]
    [ApiGroup(GroupName = ApiGroupEnum.Chat)]
    [ApiController]
    public class ChatUserController : ControllerBase
    {
        private readonly IChatUserService chatUserSvc;
        public ChatUserController(IChatUserService chatUserService)
        {
            chatUserSvc = chatUserService;
        }

        /// <summary>
        /// 查询聊天好友
        /// </summary>
        /// <returns></returns>
        [AllowOnline]
        [HttpGet()]
        public async Task<ListRet<ChatUserModel>> GetChatUserList()
        {
            var list = await chatUserSvc.GetChatUserList();

            return new ListRet<ChatUserModel> { DataList = list };
        }

        /// <summary>
        /// 不显示聊天
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AllowOnline]
        [HttpGet("{id}")]
        public async Task<bool> Hide(long id)
        {
            return await chatUserSvc.Hide(id);
        }

        /// <summary>
        /// 删除聊天
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AllowOnline]
        [HttpDelete("{id}")]
        public async Task<bool> Delete(long id)
        {
            return await chatUserSvc.Delete(id);
        }

        /// <summary>
        /// 好友列表点击发送消息，如果是隐藏状态，则改为显示，创建聊天好友列表
        /// </summary>
        /// <param name="friendId"></param>
        /// <returns></returns>
        [AllowOnline]
        [HttpGet("{friendId}")]
        public async Task<ObjectRet<ChatUserModel>> Create(long friendId)
        {
            return await chatUserSvc.Create(friendId);
        }
    }
}
